home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / Checkpoint / cPLog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  3.2 KB  |  151 lines

  1.  
  2. #ifdef CHECKPOINT
  3.  
  4. /*
  5.  * @(#)cPLog.c    1.4  2/23/90
  6.  */
  7.  
  8. /*
  9.   cPLog.c - Emerald checkPoint log file manager
  10.  
  11.   Copyright 1987, 1988 Clinton Jeffery
  12.   Last edit: 4/28/88
  13.  
  14.   See ../h/cPLog.h for an account of what is going on here.
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <ndbm.h>
  19. #include "Kernel/h/stdTypes.h"
  20. #include "Kernel/h/emTypes.h"
  21. #include "Kernel/h/kmdTypes.h"
  22. #include "Kernel/h/mmMsgDefs.h"
  23. #include "Kernel/h/cPLog.h"
  24. #include "Kernel/h/cPDBM.h"
  25. #include "Kernel/h/replicant.h"
  26.  
  27. extern ODP OTLookup();
  28.  
  29. /* Log file private variables */
  30. #define     CPFILENAME        "CheckPoint"
  31. #define     CPNEWLOGEXTENSION ".cppnewlog"
  32.  
  33. extern char NODEDIR[];
  34. extern void OTInsert();
  35. extern HResult RecoverItemHandler();
  36.  
  37. static char LFName[200];
  38.  
  39. #ifdef CPNEWLOG
  40. static char newLFName[200];
  41. #endif
  42.  
  43.  
  44. /* logFILE descriptors */
  45. FILE *LF;
  46.  
  47. #ifdef CPNEWLOG
  48. FILE *newLF;
  49. #endif
  50.  
  51. long CP_StartEntry(obj,f)
  52. OID obj;
  53. FILE *f;
  54. {
  55.   long retval;
  56.   char *strcpy();
  57.  
  58.   retval = ftell(f);
  59.   CP_replicant->rep_Signature = REPSIGNATURE;
  60.   CP_replicant->nextOID = obj;
  61.   return retval;
  62. }
  63.  
  64. /*
  65.   init_Recover opens the log file specified for reading/writing.
  66.   -DCPNEWLOG causes it to also open strcat(name,".cpnewlog") for writing.
  67.   end_Recover seeks to the end of the log file; -DCPNEWLOG causes it
  68.   to instead close both files, delete the old log file, and rename and
  69.   reopen the new log file to the old name.
  70. */
  71.  
  72. CP_InitRecover()
  73. {
  74.   (void) sprintf(LFName, "%s/%s", NODEDIR, CPFILENAME);
  75.  
  76. #ifdef CPNEWLOG  /* open the new log file ("name.cppnewlog") for writing */
  77.   (void) sprintf(newLFName,"%s%s",LFName,".cppnewlog");
  78.  
  79.   if((newLF = fopen(newLFName,"a+"))==NULL){
  80.     FAIL("CP_InitRecover can't open newlogfile\n");
  81.   }
  82. #endif
  83.  
  84.   /* open the old log file ("name") for reading/writing */
  85.   if((LF = fopen(LFName,"a+"))==NULL) {
  86.     FAIL("CP_InitRecover cannot open logfile\n");
  87.   }
  88.   SUCCEED;
  89. }
  90.  
  91. CP_EndRecover()
  92. {
  93. #ifdef CPNEWLOG
  94.   char command[256];
  95.  
  96.   CP_SwitchDbase();
  97.   fclose(LF);
  98.   fclose(newLF);
  99.   (void) sprintf((char *)command,"mv %s %s",newLFName, LFName);
  100.   system((char *)command);
  101.   if((LF = fopen(LFName,"a+"))==NULL) {
  102.     FAIL("CP_EndRecover cannot open new logfile\n");
  103.   }
  104. #endif
  105.   if(fseek(LF,0L,2)) {
  106.     FAIL("CP_EndRecover cannot seek to end of logfile\n");
  107.   }
  108.   SUCCEED;
  109. }
  110.  
  111. /*
  112.   CP_Recover builds up an object and places it into the object table,
  113.   including the recursive loading of local and attached objects that
  114.   checkpointed with it.
  115. */
  116. CP_Recover(newOTE)
  117. GODP newOTE;
  118. {
  119.   replicantPtr rp;
  120.  
  121. #ifdef CPNEWLOG
  122.   long offset;
  123. #endif
  124.  
  125.   KMDTrace("Recover", 4, "In CP_Recover with ote (0x%08x)\n", newOTE);
  126.   if((rp=replicant_diskread(newOTE))==((replicantPtr)(-1))){
  127.     FAIL("CP_Recover diskread fails\n");
  128.   }
  129.  
  130. #ifdef CPNEWLOG
  131.   if((offset = replicant_diskwrite(rp,newLF))<0) {
  132.     FAIL("CP_Recover diskwrite fails\n");
  133.   }
  134.   KMDTrace("Recover", 4, "CP_Recover writes copy to new file\n", newOTE);
  135. #endif
  136.  
  137.   /* reconstruct object's data area, load code,
  138.      and execute recovery process all from within here. */
  139.   RecoverItemHandler(rp,(ODP)newOTE);
  140.  
  141. #ifdef CPNEWLOG
  142.   /* update the dbase */
  143.   if(CP_WriteDbase((ODP)newOTE,offset,newOTE->cPSize,newCP_DBM)<0)
  144.     FAIL("CP_Recover write to update DBase fails\n");
  145. #endif
  146.  
  147.   if(newOTE->ownOID == 0) FAIL("CP_Recover sees NULL OID\n");
  148.   SUCCEED;
  149. }
  150. #endif CHECKPOINT
  151.